import {
  wxRequest
} from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTitleActive: 0,
    pageNo: 1,
    hasNextPage: false,
    pageData: {},
    toView: 'item0',
    list: [],
    auditStatus: 0,
  },

  goVlogDetail(e) {
    const id = e.currentTarget.dataset.id;
    if (this.data.auditStatus == 0) {
      wx.navigateTo({
        url: `/pages/square/details/index?id=${id}&isAudit=${true}`,
      })
    } else {
      wx.navigateTo({
        url: `/pages/square/details/index?id=${id}`,
      })
    }
  },
  handleView(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/square/details/index?id=${id}`,
    })
  },
  goVlogDetail(e) {
    const id = e.currentTarget.dataset.id;
    if (this.data.auditStatus == 0) {
      wx.navigateTo({
        url: `/pages/square/details/index?id=${id}&isAudit=${true}`,
      })
    } else {
      wx.navigateTo({
        url: `/pages/square/details/index?id=${id}`,
      })
    }
  },

  //删除
  handlDelet: function (e) {
    var id = e.currentTarget.dataset.id;
    var that = this;
    wx.showModal({
      title: '提示',
      confirmText: '确定',
      cancelText: '取消',
      content: '确定删除该内容',
      success: function (res) {
        if (res.confirm) {
          that.delectRequest(id)
        }
      }
    })
  },
  delectRequest: function (id) {
    var that = this
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + "/com/protected/vlog/deleteById",
      method: 'POST',
      data: { id }
    }, (res) => {
      console.log(res)
      wx.showToast({
        title: "删除成功",
      })
      that.getComList()
    })
  },

  getComList() {
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/com/protected/vlog/findList',
      method: 'POST',
      data: {
        auditStatus: this.data.auditStatus == 4 ? null : this.data.auditStatus,
        pageNo: this.data.pageNo,
        hasNextPage: this.data.hasNextPage
      }
    }, (res) => {
      console.log(res);
      if (res?.list) {
        this.setData({
          pageData: res.page,
          pageNo: res.page.pageNo,
          list: res.list,
          hasNextPage: res.page.hasNextPage,
        })
      }
    })
  },
  //点击导航
  navSwitch: function (e) {
    // console.log(e.currentTarget.dataset.index)
    let index = e.currentTarget.dataset.index;
    this.setData({
      auditStatus: index,
      pageNo: 1,
      hasNextPage: false,
    })
    this.getComList();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getComList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      pageNo: 1,
    }),
      this.getComList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getlist();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})